/**
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.solarchallenge.client.gwtui.widgets.usaddress;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.solarchallenge.client.gwtui.mvpinterfaces.View;
import com.google.solarchallenge.client.gwtui.widgets.solarchallengeheaderbar.SolarChallengeHeaderBarDisplay;
import com.google.solarchallenge.shared.dtos.UsAddressDto;

/**
 * View for UsAddress Widget.
 *
 * @author Arjun Satyapal
 */
public class UsAddressView extends View implements UsAddressDisplay {
  @UiField
  TextBox textBoxAddress1;
  @UiField
  TextBox textBoxAddress2;
  @UiField
  TextBox textBoxCity;
  @UiField
  TextBox textBoxState;
  @UiField
  TextBox textBoxZip;

  private static RegisterApproverViewUiBinder uiBinder = GWT
      .create(RegisterApproverViewUiBinder.class);

  interface RegisterApproverViewUiBinder extends
      UiBinder<Widget, UsAddressView> {
  }

  public UsAddressView() {
    initWidget(uiBinder.createAndBindUi(this));
  }

  @Override
  public SolarChallengeHeaderBarDisplay getSolarChallengeHeaderPanel() {
    return null;
  }

  @Override
  public TextBox getTextBoxAddress1() {
    return textBoxAddress1;
  }

  @Override
  public TextBox getTextBoxAddress2() {
    return textBoxAddress2;
  }

  @Override
  public TextBox getTextBoxCity() {
    return textBoxCity;
  }

  @Override
  public TextBox getTextBoxState() {
    return textBoxState;
  }

  @Override
  public TextBox getTextBoxZip() {
    return textBoxZip;
  }

  @Override
  public UsAddressDto getValuesAsDto() {
    return new UsAddressDto.Builder().setAddress1(textBoxAddress1.getText())
        .setAddress2(textBoxAddress2.getText()).setCity(textBoxCity.getText())
        .setState(textBoxState.getText()).setZip(textBoxZip.getText()).build();
  }

  @Override
  public void updateValuesFromDto(UsAddressDto dto) {
    textBoxAddress1.setText(dto.getAddress1());
    textBoxAddress2.setText(dto.getAddress2());
    textBoxCity.setText(dto.getCity());
    textBoxState.setText(dto.getState());
    textBoxZip.setText(dto.getZip());
  }

  @Override
  public void setEnabled(boolean enabled) {
    textBoxAddress1.setEnabled(enabled);
    textBoxAddress2.setEnabled(enabled);
    textBoxCity.setEnabled(enabled);
    textBoxState.setEnabled(enabled);
    textBoxZip.setEnabled(enabled);
  }
}
